import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Dialog-对话框',
      home: Scaffold(
        appBar: AppBar(
          title: Text('Dialog-对话框'),
        ),
        body: DemoPage(),
      ),
    );
  }
}

class DemoPage extends StatefulWidget{
  @override
  DemoPageState createState() => DemoPageState();
}

class DemoPageState extends State{
  void showAboutDialog(BuildContext context){
    showDialog(context:context, builder:(_) => AboutDialog(
      applicationName: 'as',
      applicationIcon: Icon(Icons.add),
      applicationVersion: 'v1.0.0',
      children: [
        Text('AboutDialog'),
      ],
    ));
  }

  void showSimpleDialog(BuildContext context){
    showDialog(context:context, builder:(BuildContext context) => SimpleDialog(
      title: Text('SimpleDialog'),
      children: [
        SimpleDialogOption(
          child: Text('1'),
          onPressed:(){
            Navigator.of(context).pop();
          }
        ),
        SimpleDialogOption(
          child: Text('2'),
          onPressed: (){
            Navigator.of(context).pop();
    }
        ),
      ],
    ));
  }

  void showAlertDialog(BuildContext context){
    showDialog(context:context, builder:(BuildContext context) => AlertDialog(
      title: Text('AlertDialog'),
      content: SingleChildScrollView(
        child: ListBody(
          children: [
            Text('SingleChildScrollView-ListBody'),
            Text('SingleChildScrollView-ListBody'),
            Text('SingleChildScrollView-ListBody'),
            Text('SingleChildScrollView-ListBody'),
            Text('SingleChildScrollView-ListBody'),
            Text('SingleChildScrollView-ListBody'),
            Text('SingleChildScrollView-ListBody'),
            Text('SingleChildScrollView-ListBody'),
            Text('SingleChildScrollView-ListBody'),
            Text('SingleChildScrollView-ListBody'),
            Text('SingleChildScrollView-ListBody'),
            Text('SingleChildScrollView-ListBody'),
            Text('SingleChildScrollView-ListBody'),
            Text('SingleChildScrollView-ListBody'),
            Text('SingleChildScrollView-ListBody'),
            Text('SingleChildScrollView-ListBody'),
            Text('SingleChildScrollView-ListBody'),
            Text('SingleChildScrollView-ListBody'),
            Text('SingleChildScrollView-ListBody'),
            Text('SingleChildScrollView-ListBody'),
            Text('SingleChildScrollView-ListBody'),
            Text('SingleChildScrollView-ListBody'),
            Text('SingleChildScrollView-ListBody'),
            Text('SingleChildScrollView-ListBody'),
            Text('SingleChildScrollView-ListBody'),
            Text('SingleChildScrollView-ListBody'),
            Text('SingleChildScrollView-ListBody'),
          ],
        ),
      ),
      actions: [
        FlatButton(onPressed: (){
          Navigator.of(context).pop();
        }, child: Text('sure')),
        FlatButton(onPressed: (){
          Navigator.of(context).pop();
        }, child: Text('cancle')),
      ],
    ));
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Dialog(
          child: Container(
            height: 400,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              children: [
                RaisedButton(
                  child:Text('showAboutDialog'),
                    onPressed: (){
                  showAboutDialog( context);
                }),
                RaisedButton(
                    child:Text('showSimpleDialog'),
                    onPressed: (){
                      showSimpleDialog( context);
                    }),
                RaisedButton(
                    child:Text('showAlertDialog'),
                    onPressed: (){
                      showAlertDialog( context);
                    }),
              ],
            ),
          ),
        )
      ],
    );
  }
}